class Admin::SwipersController < AdminController
  def index
    @swipers = Swiper.order("sort ASC").page(params[:page]).per(params[:per])
  end

  def new
    @swiper = Swiper.new
  end

  def create
    @swiper = Swiper.new swiper_params
    if @swiper.save
      redirect_to admin_swipers_path, notice: "保存成功！"
    else
      redirect_to admin_swipers_path, notice: "保存失败！"
    end
  end

  def edit
    @swiper = Swiper.find params[:id]
  end

  def update
    @swiper = Swiper.find params[:id]
    if @swiper.update swiper_params
      redirect_to admin_swipers_path, notice: "更新成功！"
    else
      redirect_to admin_swipers_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @swiper = Swiper.find params[:id]
    if @swiper.destroy
      redirect_to admin_swipers_path, notice: "删除成功."
    else
      redirect_to admin_swipers_path, notice: "删除失败."
    end
  end

  private

  def swiper_params
    params.require(:swiper).permit(:image, :url, :sort)
  end
end
